<?php

use yii\helpers\Html;
use yii\grid\GridView;


$this->title = '合同列表';
$this->params['breadcrumbs'][] = $this->title;
?>

<style type="text/css">
    .cs1{margin:2px 5px;} 
</style>

<div class="product-index">

    <div class="box">
        <div class="box-header">
            <?= Html::a(Yii::t('app', '创建合同'), ['create'], ['class' => 'btn btn-success']) ?>
        </div>
        <div class="box-body">
        <p>
             <?php echo $this->render('_search', ['model' => $searchModel,'customer'=>$customer]); ?>
        </p>

            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'layout'  =>  "{items}\n{summary}\n{pager}",
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],

                    [
                        'attribute' => 'code',
                        'value' => function ($model) {
                                return $model->code;
                        },
                    ],

                    [
                        'attribute' => '客户名称',
                        'value' => function ($model) {
                                return $model->customer->name;
                            },
                    ],
                    
                    [
                      'attribute' => 'sale_id',
                      'value' => function($model){

                            return $model->saleName;
                      }
                    ],
                    
                    
                    [
                        'attribute' => 'sale_currency',
                        'value' => function ($model) {
                                return $model->sale_currency;
                        },
                    ],
                    
                    [
                        'attribute' => 'sale_price',
                        'value' => function ($model) {
                                return $model->sale_price;
                        },
                    ],

                    [
                        'attribute' => 'status',
                        'value' => function ($model) {
                                return isset(Yii::$app->params['contract_status'][$model->status])?Yii::$app->params['contract_status'][$model->status]:'';
                            },
                    ],

                    [
                      'attribute' => 'user_id',
                      'value' => function($model){

                            return $model->userName;
                      }
                    ],

                    [
                        'label'=>'操作',
                        'format'=>'raw',
                        'value' => function($model){

                            $url  = sprintf("/contract/contract/view?id=%d", $model->id); //查看
                            $url2  = sprintf("/contract/contract/update?id=%d", $model->id); //更新

                            $url3 = sprintf("/contract/contract/business?id=%d", $model->id); //商务操作
                            $url4  = sprintf("/contract/contract/finance?id=%d", $model->id); //财务操作

                            
                            $str  = Html::a('查看',$url,['title' =>'查看','class'=>'btn btn-info btn-xs cs1',]);

                            if($model->user_id == \yii::$app->user->id && $model->status == 1){
                                
                                $str .= Html::a('更新',$url2,['title' =>'更新','class'=>'btn btn-warning btn-xs cs1',]);

                                $str .= Html::a('删除合同', ['del', 'id' => $model->id], ['class' => 'btn btn-danger btn-xs cs1','data' => [
                                        'confirm' => Yii::t('app', '你确定要删除合同吗?'),
                                        'method' => 'post',
                                ],]);
                            }
                            
                            $str  .= Html::a('商务操作',$url3,['title' =>'商务操作','class'=>'btn btn-primary btn-xs cs1',]);

                            $str  .= Html::a('财务操作',$url4,['title' =>'财务操作','class'=>'btn btn-success btn-xs cs1',]);
                                
                            
                           
                            return $str;
                         }
                    ],

                ],
            ]); ?>
        </div>
    </div>
</div>

